﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using CapstoneWinPhone.Data;

namespace CapstoneWinPhone
{
    public partial class ExpenseLogViewer : PhoneApplicationPage
    {
        int _selectedItem;
        public ExpenseLogViewer()
        {
            InitializeComponent();
            Loaded += FillInPage;
        }

        private void FillInPage(object sender, RoutedEventArgs args)
        {
            string selectedIndex;
            int index = 0;
            if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
            {
                index = int.Parse(selectedIndex);
                _selectedItem = index;
            }

            PageTitle.Text = DataHolder._currentUser._ExpenseLogs.Reverse().ToArray()[_selectedItem]._nameOfLog;
            listBox1.ItemsSource = DataHolder._currentUser._ExpenseLogs.Reverse().ToArray()[_selectedItem]._ListOfExpenses.OrderByDescending(e => e.Amount);
            totalAmountTextBlock.Text = "$" + DataHolder._currentUser._ExpenseLogs.Reverse().ToArray()[_selectedItem]._totalAmount.ToString("#.##");
        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
    }
}